//
//  BetView.m
//  K8彩票
//
//  Created by zhoubo on 2017/6/7.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "BetView.h"
#import "BetButton.h"
#import "Config.h"
#import "HomeVC.h"

#import "KuaiVC.h"
@interface BetView()
@property (nonatomic,strong) NSMutableArray* imgs;

@property (weak, nonatomic) IBOutlet UIView *radiusView;

@property (weak, nonatomic) IBOutlet UIImageView *img1;

@property (weak, nonatomic) IBOutlet UIImageView *img2;
@property (weak, nonatomic) IBOutlet UIImageView *img3;
@property (weak, nonatomic) IBOutlet BetButton *betButton;
@property (weak, nonatomic) IBOutlet UILabel *titlelabel;

@end

@implementation BetView

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {

        self.imgs = [[NSMutableArray alloc]initWithCapacity:6];
        for (int i = 1; i<7; ++i) {
            [self.imgs addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d",i]]];
        }
        


    }
    return self;
}

-(void)awakeFromNib
{
    [super awakeFromNib];
    [self startAnimation:self.img1];
    [self startAnimation:self.img2];
    [self startAnimation:self.img3];
    
    self.radiusView.backgroundColor = [UIColor colorWithWhite:235/255.0 alpha:1];
    self.img1.backgroundColor = [UIColor colorWithWhite:235/255.0 alpha:1];
    self.img2.backgroundColor = [UIColor colorWithWhite:235/255.0 alpha:1];
    self.img3.backgroundColor = [UIColor colorWithWhite:235/255.0 alpha:1];

    
    self.img1.contentMode = UIViewContentModeScaleAspectFit;
    self.img2.contentMode = UIViewContentModeScaleAspectFit;
    self.img3.contentMode = UIViewContentModeScaleAspectFit;
    
    if([self.betButton.titleLabel.text  isEqual: @"Details"])
    {
        [self.betButton.titleLabel setFont:[UIFont systemFontOfSize:5]];
    
    }

}



-(void)layoutSubviews
{
    [super layoutSubviews];
    
    
    
    CGFloat height = self.radiusView.frame.size.height;
    self.radiusView.layer.cornerRadius = height/2;
    self.radiusView.layer.masksToBounds = YES;



//    self.img1.image = [UIImage imageNamed:@"1"];
//    self.img2.image = [UIImage imageNamed:@"5"];
//    self.img3.image = [UIImage imageNamed:@"6"];

}
- (IBAction)betButtonClick:(id)sender {
    
    // push到快三界面
    KuaiVC* vc = [[KuaiVC alloc]init];
    
    //获取通知中心单例对象
//    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];

    
    //创建一个消息对象
    NSNotification * notice = [NSNotification notificationWithName:@"fast3" object:nil userInfo:@{@"vc":@"jiangsufast3"}];
    //发送消息
    [[NSNotificationCenter defaultCenter]postNotification:notice];
    
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)setModel:(IssueModel *)model
{
    _model = model;
    NSDate* date = [NSDate date];

    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *components = [cal components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:date];
    
    [UIView animateWithDuration:1 animations:^{
        self.titlelabel.alpha = 1;
        self.img1.alpha = 1;
        self.img2.alpha = 1;
        self.img3.alpha = 1;
    }];

    //®®®®®®®执行动画的时候设置图片可能会失败
    self.titlelabel.text = [NSString stringWithFormat:NSLocalizedString(@"江苏快3 第%@期", @"江苏快3 第%@期"),model.issue];

    
    NSLog(@"%ld---%ld---%ld",model.num1,model.num2,model.num3);
//    [self.img1 stopAnimating];
//    [self.img2 stopAnimating];
//    [self.img3 stopAnimating];
//    
    NSString* numm1=[NSString stringWithFormat:@"%ld",(long)model.num1];
    NSString *numm2 = [NSString stringWithFormat:@"%ld",(long)model.num2];
    NSString *numm3 = [NSString stringWithFormat:@"%ld",(long)model.num3];

    
    self.img1.image = [UIImage imageNamed:numm1];
    self.img2.image = [UIImage imageNamed:numm2];
    self.img3.image = [UIImage imageNamed:numm3];


}

-(void)startAnimation:(UIImageView*)imgview
{
//    //设置动画数组
//    [imgview setAnimationImages:self.imgs];
//    //设置动画播放次数
//    [imgview setAnimationRepeatCount:10];
//    //设置动画播放时间
//    [imgview setAnimationDuration:0.5];
//    //开始动画
//    [imgview startAnimating];
    
    
}

@end
